package com.atguigu.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class juctest {
    public static void main(String[] args) {
        paip paip = new paip();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                paip.mai();}
            }
        },"a").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    paip.mai();}
            }
        },"b").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    paip.mai();}
            }
        },"c").start();

    }
}
class paip{
    int Piao=50;
    Lock lock=new ReentrantLock();
    public void mai(){
        lock.lock();
        try {
            if (Piao>0){
                System.out.println( Thread.currentThread().getName()+"=卖出第"+Piao-- +"还有"+Piao);
            }
        }finally {
            lock.unlock();
        }
    }


}
